package www;

//抽象动物类
abstract class Animal {
 protected String name;
 protected String type;
 protected String breed;
 protected double price;

 public Animal(String name, String type, String breed, double price) {
     this.name = name;
     this.type = type;
     this.breed = breed;
     this.price = price;
 }

 // 吃饭：
 public void eat() {
     System.out.println(name + "正在吃饭。");
 }

 // 睡觉：
 public void sleep() {
     System.out.println(name + "正在睡觉。");
 }

 // 玩：
 public void play() {
     System.out.println(name + "正在玩耍。");
 }

 // 抽象方法：叫
 public abstract void makeSound();
}

//小猫类：
class Cat extends Animal {
 public Cat(String name, String type, String breed, double price) {
     super(name, type, breed, price);
 }


 public void play() {
     super.play(); // 调用父类的play方法输出“正在玩耍”
     makeSound(); // 小猫在玩耍时会叫
 }


 public void makeSound() {
     System.out.println(name + "说：喵！");
 }
}

//小狗类：
class Dog extends Animal {
 public Dog(String name, String type, String breed, double price) {
     super(name, type, breed, price);
 }


 public void play() {
     super.play(); // 调用父类的play方法输出“正在玩耍”
    
 }
 public void bark() {

     makeSound();

 }

 public void makeSound() {
     System.out.println(name + "说：汪！");
 }

}


public class Main {
 public static void main(String[] args) {
     // 创建小猫对象：
     Cat cat1 = new Cat("小猫1", "猫", "未知品种", 150.0);
     Cat cat2 = new Cat("小猫2", "猫", "未知品种", 200.0);

     // 创建小狗对象：
     Dog dog1 = new Dog("小狗1", "狗", "未知品种", 300.0);
     Dog dog2 = new Dog("小狗2", "狗", "未知品种", 250.0);

     // 测试小猫和小狗的行为：
     cat1.eat();
     cat1.sleep();
     cat1.play(); // 小猫在玩耍时会叫

     dog1.eat();
     dog1.sleep();
     dog1.bark();
   

     // 第二个实例的测试：
     cat2.eat();
     cat2.sleep();
 //    cat2.play(); // 小猫在玩耍时会叫，所有这里另一只不玩

     dog2.eat();
     dog2.sleep();
     dog2.play(); // 小狗在玩耍时不会叫

 }
}